/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.opensymphony.xwork2.validator.annotations.DateRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Thai Ha Cong
 */
public class Customer implements Serializable {

    private Integer idCustomer;
    private String firstName;
    private String lastName;
    private String address;
    private String phone;
    private Date dob;
    private String email;
    private Memberaccount memeberaccount;
    private List<Order> orderList;

    public Customer() {
    }

    public Customer(Integer idCustomer) {
        this.idCustomer = idCustomer;
    }

    public Customer(Integer idCustomer, String firstName, String lastName, String address, String phone, Date dob, String email) {
        this.idCustomer = idCustomer;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.phone = phone;
        this.dob = dob;
        this.email = email;
    }

    public Customer(Integer idCustomer, String firstName, String lastName, String address, String phone, Date dob, String email, Memberaccount memeberaccount) {
        this.idCustomer = idCustomer;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.phone = phone;
        this.dob = dob;
        this.email = email;
        this.memeberaccount = memeberaccount;
    }

    public Integer getIdCustomer() {
        return idCustomer;
    }

    public void setIdCustomer(Integer idCustomer) {
        this.idCustomer = idCustomer;
    }

    public String getFirstName() {
        return firstName;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "FirstName is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "FirstName should contains 2-30 characters.", minLength = "2", maxLength = "30")})
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "LastName is required.")},
            stringLengthFields = {
        @StringLengthFieldValidator(message = "LastName should contains 2-30 characters.", minLength = "2", maxLength = "30")})
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getAddress() {
        return address;
    }

    @RequiredStringValidator(message = "Address is required.")
    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    @RequiredStringValidator(message = "Phone Number is required.")
    @RegexFieldValidator(message = "Invalid Phone Number.", expression = "^0\\d{9,10}$")
    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Date getDob() {
        return dob;
    }

//    @RequiredStringValidator(message = "Date of Birth is required.")
    @DateRangeFieldValidator(message = "Invalid Date of Birth", min = "01/01/1922", max = "12/31/2012")
    public void setDob(Date dob) {
        this.dob = dob;
    }

    public String getEmail() {
        return email;
    }

    @Validations(
            requiredStrings = {
        @RequiredStringValidator(message = "E-mail is required.")},
            emails = {
        @EmailValidator(message = "Invalid E-mail")})
    public void setEmail(String email) {
        this.email = email;
    }

    public Memberaccount getMemeberaccount() {
        return memeberaccount;
    }

    public void setMemeberaccount(Memberaccount memeberaccount) {
        this.memeberaccount = memeberaccount;
    }

    public List<Order> getOrderList() {
        return orderList;
    }

    public void setOrderList(List<Order> order1List) {
        this.orderList = order1List;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCustomer != null ? idCustomer.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.idCustomer == null && other.idCustomer != null) || (this.idCustomer != null && !this.idCustomer.equals(other.idCustomer))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Customer[ idCustomer=" + idCustomer + " ]";
    }
}
